#pragma once

#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <cstdlib>
#include "Common.hpp"

namespace SocketModule
{
    // 模版方法实现
    class Socket
    {
    public:
        virtual ~Socket() {}
        virtual void SocketOrDie() = 0;
        virtual bool BindOrDie() = 0;
        virtual bool ListenOrDie() = 0;
        virtual int Accept() = 0;
    public:
        void BuidTcpSocketMethod()
        {
            SocketOrDie();
            BindOrDie();
            ListenOrDie();
        }

        // void BuidUdpSocketMethod()
        // {
        //     SocketOrDie();
        //     BindOrDie();
        // }
    };

    class TcpSocket : public Socket
    {
    public:
        ~TcpSocket() {}
        void SocketOrDie() override
        {
            _sockfd = socket(AF_INET, SOCK_DGRAM, 0);
            if(_sockfd < 0)
            {
                exit()
            }
        }
        bool BindOrDie() override
        {
            return true;
        }
        bool ListenOrDie() override
        {
            return true;
        }
        int Accept() override
        {
            return 0;
        }
    private:
        int _sockfd;
    };
}